package cn.edu.zime.tjh.iotapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private String accessToken; // 用于存储 access_token
    private String role; // 用于存储用户角色
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_host);

// 从 Intent 中获取传递过来的 access_token 和 role
        Intent intent = getIntent();
        if (intent != null) {
            accessToken = intent.getStringExtra("access_token");
            role = intent.getStringExtra("role");

            // 打印 token 和 role 到日志（可选）
            System.out.println("Access Token: " + accessToken);
            System.out.println("Role: " + role);

            // 显示欢迎信息（可选）
            Toast.makeText(this, "欢迎:" + accessToken, Toast.LENGTH_SHORT).show();
        } else {
            // 如果没有传递 token 和 role，提示错误
            Toast.makeText(this, "未接收到用户信息，请重新登录", Toast.LENGTH_SHORT).show();
            finish(); // 关闭当前界面
        }

        // 为 mystate 按钮设置点击事件
        findViewById(R.id.mystate).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到 MystateActivity，并传递 token 和 role
                Intent mystateIntent = new Intent(MainActivity.this, MystateActivity.class);
                mystateIntent.putExtra("access_token", accessToken);
                mystateIntent.putExtra("role", role);
                startActivity(mystateIntent);
            }
        });

    }

    public void equipment(View V){
        Intent intent = new Intent(MainActivity.this, AddEquipment.class);
        startActivity(intent);
    }
    public void Presure(View V){
        Intent intent = new Intent(MainActivity.this, PressureActivity.class);
        startActivity(intent);
    }
    public void Light(View V){
        Intent intent = new Intent(MainActivity.this, LightActivity.class);
        startActivity(intent);
    }
    public void Altiduede(View V){
        Intent intent = new Intent(MainActivity.this, AltitudeActivity.class);
        startActivity(intent);
    }

    public void Location(View V){
        Intent intent = new Intent(MainActivity.this, LocationActivity.class);
        startActivity(intent);
    }

    public void Scan(View V){
        Intent intent = new Intent(MainActivity.this, ScanActivity.class);
        startActivity(intent);
    }


}
